//
//  XZNewsCaseContentCell.m
//  Teecloud
//
//  Created by PC on 2018/10/19.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZNewsCaseContentCell.h"
#import "XZRemarkList.h"
#import "GMlevelView.h"
@interface XZNewsCaseContentCell ()
//头像
@property (weak, nonatomic) IBOutlet UIImageView *commentUserIcon;
//名称
@property (weak, nonatomic) IBOutlet UILabel *commentUsername;
//时间
@property (weak, nonatomic) IBOutlet UILabel *commentTime;
//内容
@property (weak, nonatomic) IBOutlet UILabel *comment;
//点赞数量
@property (weak, nonatomic) IBOutlet UILabel *likeCount;
//点赞的按钮
@property (weak, nonatomic) IBOutlet UIButton *likeButton;
//等级view
@property (weak, nonatomic) IBOutlet GMlevelView *levelView;
//等级view宽度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *levelViewWidth;


@end

@implementation XZNewsCaseContentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(XZRemarkList *)model{
    _model = model;
    [self.commentUserIcon yy_setImageWithURL:[NSURL URLWithString:model.RemarkUserInfo.HeadUrl] placeholder:DefealtImg];
    self.commentUsername.text = model.RemarkUserInfo.UserName;
    self.commentTime.text = model.RemarkTime;
    self.comment.text = model.Remark;
    self.likeCount.text = [NSString stringWithFormat:@"%@",model.LikeCount];
    if (!model.IsLike) {//是否已经点赞
        [self.likeButton setImage:[UIImage imageNamed:@"finger-gray-64"] forState:UIControlStateNormal];
    }else{
        [self.likeButton setImage:[UIImage imageNamed:@"finger-blue-64"] forState:UIControlStateNormal];
    }

    //等级
    NSInteger totalNum = model.RemarkUserInfo.GradeIconCount.CrownCount +model.RemarkUserInfo.GradeIconCount.SunCount+model.RemarkUserInfo.GradeIconCount.MoonCount+model.RemarkUserInfo.GradeIconCount.StarCount;
    self.levelViewWidth.constant = totalNum *20;
    [self.levelView setCrownCount:model.RemarkUserInfo.GradeIconCount.CrownCount SunCount:model.RemarkUserInfo.GradeIconCount.SunCount MoonCount:model.RemarkUserInfo.GradeIconCount.MoonCount StarCount:model.RemarkUserInfo.GradeIconCount.StarCount];
    
    //计算文字高度 加上10的间距
    CGFloat commentSize = [self getLabelHeightWithText:model.Remark width:kScreenWidth - 80 font:14.0f];
    model.cellHeight = CGRectGetMinY(self.comment.frame)+commentSize+10;
    
}
/**
 *
 *计算文字高度
 */
- (CGFloat)getLabelHeightWithText:(NSString *)text width:(CGFloat)width font: (CGFloat)font{
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
    return rect.size.height;
}
//点赞
- (IBAction)likeButtonAction:(UIButton *)sender {
    if (self.likeBlock) {
        self.likeBlock(self.model,self.indexPath);
    }
}

@end
